package com.sh.example.provider;


import com.sh.example.common.service.UserService;
import com.sh.rpc.RpcApplication;
import com.sh.rpc.confige.RegistryConfig;
import com.sh.rpc.confige.RpcConfig;
import com.sh.rpc.model.ServiceMetaInfo;
import com.sh.rpc.registry.LocalRegistry;
import com.sh.rpc.registry.Registry;
import com.sh.rpc.registry.RegistryFactory;
import com.sh.rpc.server.VertxHttpService;
import com.sh.rpc.server.tcp.VertTcpService;

public class EasyProvideExample {
    public static void main(String[] args) {

        RpcApplication.init();   // 初始化框架


                           //    com.sh.example.common.service.UserService
        LocalRegistry.register(UserService.class.getName(), UserServiceImpl.class);


        String serviceName = UserService.class.getName();
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(serviceName);
        serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());   // localhost
        serviceMetaInfo.setServicePort(rpcConfig.getServerPort());     // 8989
        try {
            registry.register(serviceMetaInfo);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
//        new VertxHttpService().doStart(RpcApplication.getRpcConfig().getServerPort());  // 启动服务
        new VertTcpService().doStart(RpcApplication.getRpcConfig().getServerPort());
    }
}
